
<!doctype html>
<html>
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge" />
		<link href="../css/main.css" type="text/css" rel="stylesheet" />
		<link href="../css/dialog.css" rel="stylesheet" type="text/css">
		<title></title>
		<style type="text/css">
			tr td:first-child {
	            text-align: right;
	            width:20%;
	        }
			tr td:nth-child(2) {
	            text-align: left;
	            width:40%;
	            padding-left: 20px;
    padding-right: 20px;
	        }
	        .save{
	            width:60px;
	                margin-top: 5px;
    margin-bottom: 5px;
	        }
	        
	        .table_list{
	               background-color: whitesmoke;
	        }
		</style>
	</head>
	<body>
		<div class="main_frame">
			<div class="position_div">
				<img src="../images/position_icon.png" />
				<i>系统管理</i><i>&gt;&gt;</i><i>个人中心</i>
			</div>
			<div class="right_div">
				<div class="search_div">
					<!-- <div class="label_div">
						<label class="text_label">姓名：</label>
						<input type="text" class="input_search" placeholder="" id="qry_name" />
					</div>
					
					<div class="label_div">
						<label class="text_label">账号：</label>
						<input type="text" class="input_search" placeholder="" id="qry_account" />
					</div>
					
					<div class="done_div">
						<button class="btn_common1 title_div2"  onclick="qryItemListBtn()">
							<i></i>搜索
						</button>
						<button style="margin-left:10px !important" class="btn_common2 newadd"   onclick="toAddForm()">
							<i></i>新增
						</button>
					</div>
                   
                    <div class="cl">&nbsp;</div> -->
                   <!--  <div>
                        <img alt="头像" src="" width="100px" height="100px"> 
                        <button style="margin-left:10px !important;top:-12px;" class="btn_common2 save" >
                            <i></i>修改
                        </button>
                    </div> -->
                    <hr/>
                    <div class="blank_div"></div>
				</div>
				<table class="table_list">
					<tr>
<!-- 						<th width="8%"></th> -->
<!-- 						<th width="15%"></th> -->
<!-- 						<th width="10%"></th> -->
<!-- 						<th width="11%">角色</th> -->
<!-- 						<th width="16%">创建时间</th> -->
<!-- 						<th class="last_td">操作</th> -->
					</tr>
					<tbody id="listbox1">
					<input type= "hidden" id="user_id_"/>
					<tr>
						<td>姓名</td>
						<td><span id="name_sp"></span><input id="name" style="display: none;" type="text" class="input_search" value=""/></td>
						<td>
							<button style="margin-left:10px !important" class="btn_common2 save editInfo" >
	                            <i></i>修改
	                        </button>
                        </td>
					</tr>
					<tr>
						<td>手机号码</td>
						<td><span id="tel_sp"></span><input id="cell_phone" type="text" style="display: none;" class="input_search" value=""/></td>
						<td><button style="margin-left:10px !important" class="btn_common2 save editInfo" >
                                <i></i>修改
                            </button></td>
					</tr>
					<tr>
                        <td>账号</td>
                        <td><span id="acc_sp"></span></td>
                        <td></td>
                    </tr>
					<tr>
						<td>密码</td>
                        <td><span id="pwd_sp">********</span><input id="pwd" type="password" style="display: none;" class="input_search" value=""/></td>
                        <td><button style="margin-left:10px !important" class="btn_common2 save editInfo" >
                                <i></i>修改
                            </button></td>
					</tr>
					<tr>
						<td>状态</td>
						<td><label>正常</label></td>
						<td></td>
					</tr>
				</tbody>
				</table>
				
			</div>
		</div>
		<script type="text/javascript" src="../js/jquery-1.10.2.min.js"></script>
		<script type="text/javascript" src="../js/common.js"></script>
		<script type="text/javascript" src="../js/dialog.js"></script>
		<script type="text/javascript" src="../js/jquery-data.js"></script>
		<script type="text/javascript">
		
		$(function(){
		     
		     $(".editInfo").click(function(){
		          var td2 = $(this).parent().parent().children().eq(1);
		          
		          if( $(this).text()=="确定"){
		              td2.find("span").show();
                      td2.find("input").hide();
                      $(this).text("修改");
                      var txtInf = $(this).parent().parent().children().eq(0).text();
                      if(td2.find("input").val()==td2.find("span").text()){
                          console.log("暂无修改");
                          return;
                      }
                      if(txtInf!="密码"){
	                      td2.find("span").text(td2.find("input").val());
                      }
                      //修改信息
                      editInfoBy(td2.find("input").attr("id"),td2.find("input").val());
		          }else{
			          td2.find("span").hide();
			          td2.find("input").show();
			          $(this).text("确定");
		          }
		     })
		})
		
		
		function editInfoBy(a,b){
		  if(a=="pwd"&&!b){
		      return;
		  }
// 		  editAccount
           var ma = {};
           ma[a]=b;
           ma.id=$("#user_id_").val();
			$.ajax({
                    url: 'editAccount', 
                    type: 'POST',
                    data:ma,
                    async: false,
                    dataType: 'json', 
                    timeout: 10000, 
                    error: function(){LQWarn('请求失败,请稍后重试');}, 
                    success: function(result){
                        console.log(result);
					}
				})
			}
		
			var yema=1;
			var pagelen=10;
			var totalPage=0;   
			function qryList(){		
// 				qryItemList();
			}
			
			$(document).ready(function(){
				getModelCodeList();
// 				qryList();
				getUserOne();
			});
			function qryList(){
// 				qryItemList();
			}
			function qryItemListBtn(){
				 yema=1;
// 				qryItemList();
			}
			
			function getUserOne(){
                $.ajax({
                    url: 'getUser', 
                    type: 'POST',
                    data:{id:0},
                    async: false,
                    dataType: 'json', 
                    timeout: 10000, 
                    error: function(){LQWarn('请求失败,请稍后重试');}, 
                    success: function(u){
                        u=u.returnObject;
                        console.log(u);
                        $("#name_sp").html(u.name);
                        $("#name").val(u.name);
                        $("#tel_sp").html(u.cellPhone);
                        $("#cell_phone").val(u.cellPhone);
                        $("#acc_sp").text(u.account);
                        $("#user_id_").val(u.id);
                    }
                });
            }
			
			function qryItemList1(){
				$.ajax({
					url: 'qryAccountList', 
					type: 'POST',
					data:{name:$("#qry_name").val(),
						yema:yema,length:pagelen},
					async: false,
					dataType: 'json', 
					timeout: 10000, 
					error: function(){LQWarn('请求失败,请稍后重试');}, 
					success: function(result){
						
						if(result.resultCode==1000){
							
							var items=result.returnObject.pageList;
							if (items && items.length > 0) {
								var rlist="";
								var item ;
								
								$.each(items,function(i){
									item = items[i];
									rlist+='<tr data-status ="'+ item.id+'"><td>'
										+ (i+1+length*(result.returnObject.curPage-1))
										+ '</td><td>' 
										+ item.name
										+ '</td><td>'
										+ item.account
										+ '</td><td>'
										+ item.cellPhone
										+ '</td><td>'
										+ item.roleName
										+'</td><td>'
										+ formatToDateTime(item.createTime)
										+'</td><td class="last_td">'
										+ '<a class="mod" title="修改" href="javascript:void(0);" onclick="toEditForm(this)">修改</a>'
										+ '<a class="del" title="删除" href="javascript:void(0);" onclick="delItem(this)">删除</a>'
										
										+ '</td></tr>';
								});
								$("#listbox1").html(rlist);
								totalPage=result.returnObject.totalPage;
								$("#nowpage").html(result.returnObject.curPage);
								$("#totalpage").html(totalPage);
								$("#totalNum").html(result.returnObject.totalNum);
								$(".turn_page").show();
							}else{
								$("#listbox1").html("");
								$(".turn_page").hide();
							}
						}
						else if(result.resultCode==1004){
							LQWarn(result.returnObject);
							window.top.location.href ="../login.jsp";
						}else{
							LQWarn(result.returnObject);
						}
					}
				});
			}
			
			var url_ = "addAccount.do";
			
			function toAddForm(){
				$(".opacity_div,.bookDetail").show();	
				url_ = "addAccount.do";
				$("#form").clearForm();
				$("#pwd").show();
				$("#account").attr("readOnly",false);
			}

			
			function itemFormSubmit(){
			//	console.log($("#form").serialize());
				
				if($("#form").checkhaveNull()){
					return;
				}
				operateObject(url_,$("#form").serialize(),function(){edit_cancel();});
				//return;
				
			}
			
			
			function toEditForm(obj){
				var id = $(obj).parents("tr").attr("data-status");
				toAddForm();
				$("#pwd").hide();
				$("#account").attr("readOnly",true);
				url_ = "editAccount.do";
				getObjectWithFillData("getUser.do",{"id":id},$("#form"));
				
			}
			
			function delItem(obj){
				
				var id = $(obj).parents("tr").attr("data-status");
				delObject('delAccount.do',{"id":id});
				
				
			}
			
			function edit_cancel(){
				$(".opacity_div,.bookDetail").hide();
			}
			
			
			function getModelCodeList(){
				$.ajax({
					url: '/boilerCloud/getRoles.do', 
					type: 'POST',
					async: false,
					traditional:true,
					dataType: 'json', 
					timeout: 10000, 
					error: function(){LQWarn('请求失败,请稍后重试');}, 
					success: function(result){
						if(result.resultCode==1000){
							//console.log(result.returnObject);
							var items = result.returnObject;
							var item;
							var html_items = "";
							
							if(items){
								for(var i=0;i<items.length;i++){
									item = items[i];
									html_items  += '<li><a href="javascript:void(0)" class="choose_a" data-status="'+items[i].ID+'" >'+ items[i].ROLENAME+'</a></li>';		
									
								}
							}
							$(".items").html(html_items);
						}
						else if(result.resultCode==1004){
							LQWarn(result.returnObject);
							window.top.location.href ="../login.jsp";
						}else{
							LQWarn(result.returnObject);
						}
					}
				});	
			}
			
		</script>
	</body>
</html>
